/**
 * Copyright (C) 2010 DustedPixels.com
 */
package com.dustedpixels.cirt.model.cpu.z80;

import com.dustedpixels.cirt.model.core.Circuit;
import com.dustedpixels.cirt.model.core.In;
import com.dustedpixels.cirt.model.core.Internal;
import com.dustedpixels.cirt.model.core.Out;
import com.dustedpixels.cirt.model.core.Pins;
import com.dustedpixels.cirt.model.core.Script;

/**
 * 8-bit register with 8-bit bus.
 * 
 * @author Michal Pociecha-Los (micapolos@gmail.com)
 */
@Circuit
public final class Reg8 {
  @In @Pins(8) public int in;
  
  @In public boolean reset;
  @In public boolean write;
  
  @Out @Pins(8) public int out;
  
  @Internal @Pins(8) public int value;
  
  @Script
  public void update() {
    if (reset) {
      value = 0xFF;
    } else if (write) {
      value = in;
    }
    
    out = value;
  }
}
